package leetcode_day._2022._202201._0110;

/**
 * @author yzh
 * @version 1.0
 * @date 2022/1/9 10:25
 * 按键持续时间最长的键
 * 算法：模拟
 */
public class _09_1629 {

    public char slowestKey(int[] releaseTimes, String keysPressed) {
        int max = releaseTimes[0], idx = 0;
        for (int i = 1; i < releaseTimes.length; i++) {
            int sub = releaseTimes[i] - releaseTimes[i - 1];
            if (sub > max) {
                idx = i;
                max = sub;
            } else if (sub == max && keysPressed.charAt(i) > keysPressed.charAt(idx)) idx = i;
        }
        return keysPressed.charAt(idx);
    }

}
